package tr.edu.metu.is.mega.server.entity;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
import javax.persistence.OneToMany;

/**
 * The persistent class for the activity database table.
 * 
 */
@NamedNativeQueries({
        @NamedNativeQuery(name = "Activity.getActivitiesByTeam", query = "SELECT * FROM Activity a LEFT JOIN Submission s ON a.PKID=s.FK_ACTIVITY WHERE s.FK_SUBMITTERTEAM=?1 OR s.FK_SUBMITTERTEAM IS NULL", resultClass = Activity.class),
        @NamedNativeQuery(name = "Activity.alertActivities", query = "select * from activity where alerttime between now()-interval '1 hour' and now()", resultClass = Activity.class) })
@Entity
public class Activity implements Serializable, tr.edu.metu.is.mega.server.core.BaseEntity {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer pkid;

    private String description;

    private Timestamp duedate;

    private Timestamp alerttime;

    private String submissiontype;

    // bi-directional many-to-one association to Course
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "fk_courseid")
    private Course course;

    // bi-directional many-to-one association to Reviewer
    @OneToMany(mappedBy = "activity", fetch = FetchType.LAZY)
    private List<Reviewer> reviewers;

    // bi-directional many-to-one association to Submission
    @OneToMany(mappedBy = "activity", fetch = FetchType.LAZY)
    private List<Submission> submissions;

    /**
     * Default constructor.
     */
    public Activity() {
    }

    /**
     * Returns pkid.
     * 
     * @return the pkid
     */
    @Override
    public Integer getPkid() {
        return pkid;
    }

    /**
     * Sets pkid value.
     * 
     * @param pkid the pkid to set
     */
    @Override
    public void setPkid(Integer pkid) {
        this.pkid = pkid;
    }

    /**
     * Returns description.
     * 
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * Sets description value.
     * 
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * Returns duedate.
     * 
     * @return the duedate
     */
    public Timestamp getDuedate() {
        return duedate;
    }

    /**
     * Sets duedate value.
     * 
     * @param duedate the duedate to set
     */
    public void setDuedate(Timestamp duedate) {
        this.duedate = duedate;
    }

    /**
     * Returns alerttime.
     * 
     * @return the alerttime
     */
    public Timestamp getAlerttime() {
        return alerttime;
    }

    /**
     * Sets alerttime value.
     * 
     * @param alerttime the alerttime to set
     */
    public void setAlerttime(Timestamp alerttime) {
        this.alerttime = alerttime;
    }

    /**
     * Returns submissiontype.
     * 
     * @return the submissiontype
     */
    public String getSubmissiontype() {
        return submissiontype;
    }

    /**
     * Sets submissiontype value.
     * 
     * @param submissiontype the submissiontype to set
     */
    public void setSubmissiontype(String submissiontype) {
        this.submissiontype = submissiontype;
    }

    /**
     * Returns course.
     * 
     * @return the course
     */
    public Course getCourse() {
        return course;
    }

    /**
     * Sets course value.
     * 
     * @param course the course to set
     */
    public void setCourse(Course course) {
        this.course = course;
    }

    /**
     * Returns reviewers.
     * 
     * @return the reviewers
     */
    public List<Reviewer> getReviewers() {
        return reviewers;
    }

    /**
     * Sets reviewers value.
     * 
     * @param reviewers the reviewers to set
     */
    public void setReviewers(List<Reviewer> reviewers) {
        this.reviewers = reviewers;
    }

    /**
     * Returns submissions.
     * 
     * @return the submissions
     */
    public List<Submission> getSubmissions() {
        return submissions;
    }

    /**
     * Sets submissions value.
     * 
     * @param submissions the submissions to set
     */
    public void setSubmissions(List<Submission> submissions) {
        this.submissions = submissions;
    }

}
